package com.example.evanproject.service.impl;

import cn.hutool.core.date.DateUnit;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.evanproject.domain.Course;
import com.example.evanproject.domain.Studentcourses;
import com.example.evanproject.mapper.CourseMapper;
import com.example.evanproject.service.StudentcoursesService;
import com.example.evanproject.mapper.StudentcoursesMapper;
import com.example.evanproject.util.DatesUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
* @author hanxiaoqi
* @description 针对表【studentcourses】的数据库操作Service实现
* @createDate 2024-03-09 21:52:13
*/
@Service
public class StudentcoursesServiceImpl extends ServiceImpl<StudentcoursesMapper, Studentcourses>
    implements StudentcoursesService{

    @Autowired
    private StudentcoursesMapper studentCoursesMapper;
    @Autowired
    private CourseMapper courseMapper;
    public Map selectisexit(Integer cId,Integer sId){
        Integer str=0;
        Integer falg=1;
       Map map=new HashMap();
        if(studentCoursesMapper.selectisexit(cId,sId)!=null){
            str=1;
        }
        Course course=courseMapper.selectById(cId);
        if(course.getCourseStarttime()!=null&&course.getCourseEndtime()!=null){
            Date startTime=course.getCourseStarttime();
            Date endTime=course.getCourseEndtime();
            Date targetTime=new Date();
            System.out.println("开始时间"+startTime.compareTo(targetTime));
            System.out.println("结束时间"+endTime.compareTo(targetTime));

            if(startTime.compareTo(targetTime)>0){
//             未开始状态
                falg=1;
            }
         if(endTime.compareTo(targetTime)<0){
//             结束状态
             falg=2;
         }
            if(startTime.compareTo(targetTime)<=0&&endTime.compareTo(targetTime)>0){
//                在范围内
                falg=3;
            }
        }
        map.put("isexit",str);
        map.put("falg",falg);

        return map;
    }

    public  Integer insertdatalist(Integer cId,Integer sId){
        return studentCoursesMapper.insertdatalist(cId,sId);
    }
}





